
var jsonList = {};
var page1 = 1;
var rows1 = 10;
var page = 1;
var rows = 10;
$(function (){
    //获取推送法案
    $.ajax({
        url: baseNews + '/api/data/push/cfg/info',
        data:{},
        success:function (res){
            console.log(res,777);
            if(res.code==0){
                $(".qj_fa").val(res.data.overall);
                $(".gx_fa").val(res.data.updating);
            }
        }
    })
    //保存推送设置
    $(".bx_fj").on('click',function (){
        var json = {
        }
        var result = JSON.stringify(json);
        zeroModal.confirm("确定保存推送设置吗？", function () {
            //置顶确认请求数据
            $.ajax({
                url: baseNews + "/api/data/push/cfg/update?overall=" + $(".qj_fa").val() + "&updating=" + $(".gx_fa").val(),
                type: "post",
                headers: { 'Content-Type': 'application/json' },
                dataType: "json",
                data: result,
                success: function (res) {
                    if (res.code == 0) {
                        location.reload();
                        console.log(res, 88888)
                    } else {
                        zeroModal.alert('保存失败');
                    }
                }
            })
        });
    })
    //获取推送列表
    //tab
    $('.tab_add').hide();
    $(".add_tab").on('click',function (){
        $('.tab_add').show();
        $(".tab_show").hide();
    })
    $(".add_ts_q").on('click',function (){
        location.reload();
    })
    //添加推送
    $(".add_ts").on('click',function (){
        var time = $(".fbs_text").val()+":00";
        if ($(".fbs_text").val()==""){
            zeroModal.alert('请选择推送时间');
            return false;
        }
        var numCount = 0;
        var ids = [];
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                //ids = ids + $(this).attr("oid") + ',';
                ids.push($(this).attr("oid"));
            }
        })
       // ids = ids.substring(0, ids.length - 1);
        if (numCount >= 1) {
            //进行下一步
            var json = {
                pushtime: time,
                sids:ids
            }
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要添加推送吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/push/add/task",
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        if (res.code == 0) {
                            location.reload();
                            console.log(res, 88888)
                        } else {
                            zeroModal.alert('取消推送失败');
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择专题');

        }

    })
    //取消推送
    $('.qx_ts').on('click',function (){
        $('.tab_add').hide();
        $(".tab_show").show();
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        ids = ids.substring(0, ids.length - 1);
        //console.log(ids, 555);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要取消推送吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/push/cancel/task?ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        if (res.code == 0) {
                            location.reload();
                            console.log(res, 88888)
                        } else {
                            zeroModal.alert('取消推送失败');
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择至少一条任务');

        }
    })
    //立即推送
    $('.ljts').on('click',function (){
        $('.tab_add').hide();
        $(".tab_show").show();
        var numCount = 0;
        var ids =[];
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids.push($(this).attr("oid"))
            }
        })
        //console.log(ids, 555);
        if (numCount >= 1) {
            //进行下一步
            console.log(ids);
            zeroModal.confirm("确定要推送吗？", function () {
                //置顶确认请求数据
                // $.ajax({
                //     url: baseNews + "/api/data/push/do/push",
                //     type: "post",
                //     data:{
                //         'sids':ids
                //     },
                //     success: function (res) {
                //         if (res.code == 0) {
                //             location.reload();
                //             console.log(res, 88888)
                //         } else {
                //             zeroModal.alert('取消推送失败');
                //         }
                //     }
                // })
                 var result = JSON.stringify(ids);
                $.ajax({
                    url:baseNews + "/api/data/push/do/push",
                    type:"post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data:result,
                    success:function (res){
                        if (res.code == 0) {
                            location.reload();
                            console.log(res, 88888)
                        } else {
                            zeroModal.alert(res.message);
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择至少一条任务');

        }
    })
})
getList();
function getList() {
    $.ajax({
        url: baseNews +"/api/data/push/tasks?page="+ page1 + "&rows=" + rows1,
        type: "get",
        data: {},
        success: function (res) {
            console.log(res, 666);
            if (res.code == 0) {
                var result = res.data;
                var list = result.list;
                console.log(list, 9999)
                var html = "";
                $("#page").paging({
                    pageNo: page1,
                    totalPage: result.totalpage,
                    totalSize: result.totals,
                    callback: function (num) {
                        page1 = num;
                        getList();
                    }
                })
                 $(".t_list").empty();
                $(list).each(function (index, key) {

                    html += `<tr>
                        <td><input type="checkbox" oid="${key.id}" class="arc_isc" /></td>
                        <td>${key.id}</td>
                        <td>${key.push?"是":"否"}</td>
                        <td>${key.sid}</td>
                        <td>${key.title}</td>
                        <td>${key.pushtime}</td>
                    </tr>`;
                })
                $(".t_list").append(html);
            }
        }
    })
    
    //分页
}
getList1();
function getList1() {
    var json = {}
    var result = JSON.stringify(json);
    $.ajax({
        url: baseNews + "/api/data/common/special/list?page=" + page + "&rows=" + rows,
        type: "post",
        headers: { 'Content-Type': 'application/json' },
        dataType: "json",
        data: result,
        success: function (res) {
            console.log(res, 333);
            if (res.code == 0) {
                var result = res.data;
                var list = result.list;
                console.log(list, 9999)
                var html = "";
                $("#page1").paging({
                    pageNo: page,
                    totalPage: result.totalpage,
                    totalSize: result.totals,
                    callback: function (num) {
                        page = num;
                        getList();
                    }
                })
                $(".zt_list").empty();
                $(list).each(function (index, key) {
                    var state = key.state;
                    var newState = "";
                    if (state == 1) {
                        newState = "待审核";
                    }
                    if (state == 2) {
                        newState = "待发布";
                    }
                    if (state == 3) {
                        newState = "已发布";
                    }
                    if (state == 10) {
                        newState = "有更新";
                    }
                    if (state == -1) {
                        newState = "审核失败";
                    }
                    if (state == -2) {
                        newState = "撤销发布";
                    }
                    html += `<tr><td><input type="checkbox"  type="checkbox" oid="${key.id}" class="arc_isc" /></td>
                        <td>${key.id}</td>
                        <td>${key.cname}</td>
                        <td>${key.title}</td>
                        <td>${key.top?"是":"否"}</td>
                        <td>${newState}</td>
                        <td>${key.articles}</td>
                        <td>${key.rtime}</td></tr>`;
                })
                $(".zt_list").append(html);
            }
        }
    })

    //分页
}